package com.wanxi.servlet.product;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.model.ProductModel;
import com.wanxi.model.ResultModel;
import com.wanxi.service.ProductService;
import com.wanxi.service.impl.ProductServiceImpl;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/product/enable")
public class ProductUpdateEnableServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //        1.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.得到前端的值

//        String enable = req.getParameter("enable");
        String id = req.getParameter("id");
//        3.封装到model
        ProductModel productModel = new ProductModel();
        productModel.setId(Tool.strToInt(id));
//        productModel.setEnable(Tool.strToInt(enable));
//        4.调用service
        ProductService productService = new ProductServiceImpl();
//        5.调用service的方法并得到返回值
        ResultModel resultModel = productService.enable(productModel);
//        6.返回前端
        resp.getWriter().println(JSONObject.toJSONString(resultModel));


    }
}
